<template>
  <div class="index-lists">
    <el-card class="!border-none mt-4" shadow="never">
      <div>
        <el-button v-perms="['customerrequire:add']" type="primary" @click="handleAdd()">
          <template #icon>
            <icon name="el-icon-Plus" />
          </template>
          添加客户要求
        </el-button>
      </div>
      <el-table class="mt-4" size="large" v-loading="pager.loading" :data="pager.lists" stripe>
        <el-table-column type="selection" width="55" />
        <el-table-column label="ID" prop="id" min-width="50" />
        <el-table-column label="案件类型" prop="caseType" min-width="100" />
        <el-table-column label="要求类型" prop="requireType" min-width="100" />
        <el-table-column label="附件名称" prop="fileName" min-width="100" />
        <el-table-column label="标题" prop="title" min-width="100" />
        <el-table-column label="创建人" prop="creatorsName" min-width="100" />
        <el-table-column label="创建时间" prop="creatorsTime" min-width="100" />
        <el-table-column label="修改人名称" prop="updateUserName" min-width="100" />
        <el-table-column label="修改时间" prop="updateTime" min-width="100" />
        <el-table-column label="操作" width="120" fixed="right">
          <template #default="{ row }">
            <el-button
              v-perms="['customerrequire:edit']"
              type="primary"
              link
              @click="handleEdit(row)"
            >
              编辑
            </el-button>
            <el-button
              v-perms="['customerrequire:del']"
              type="danger"
              link
              @click="handleDelete(row.id)"
            >
              删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="flex justify-end mt-4">
        <pagination v-model="pager" @change="getLists" />
      </div>
    </el-card>
    <edit-popup v-if="showEdit" ref="editRef" @success="getLists" @close="showEdit = false" />
  </div>
</template>
<script lang="ts" setup name="customerrequire">
import { customerRequireDelete, customerRequireLists } from '@/api/customer/customerRequire'
import { usePaging } from '@/hooks/usePaging'
import feedback from '@/utils/feedback'
import EditPopup from './edit.vue'
const editRef = shallowRef<InstanceType<typeof EditPopup>>()
const showEdit = ref(false)
const queryParams = reactive({
  caseType: ''
})

const { pager, getLists, resetPage, resetParams } = usePaging({
  fetchFun: customerRequireLists,
  params: queryParams
})

const handleAdd = async () => {
  showEdit.value = true
  await nextTick()
  editRef.value?.open('add')
}

const handleEdit = async (data: any) => {
  showEdit.value = true
  await nextTick()
  editRef.value?.open('edit')
  editRef.value?.getDetail(data)
}

const handleDelete = async (id: number) => {
  await feedback.confirm('确定要删除？')
  await customerRequireDelete({ id })
  feedback.msgSuccess('删除成功')
  getLists()
}

getLists()
</script>
